<?php

class SqlResult {

	//Created from mysql_query( ... )
	private $sqlResource;

	__construct( $resource ){
		if( !$resource ){
			//what?
			die("SqlResult created without a resource");
		}
		$sqlResource = $resource;
	}

	// fetchRow () -> Array | NULL
	// wraps mysql_fetch_assoc(), returns an array representing the row, or NULL if there is no more to read
	public function fetchRow(){
		$row = NULL;
		if( $sqlResource ){
			$row = mysql_fetch_assoc( $sqlResource );
		}
		if( ! $row ){
			$this->free();
			return NULL;
		}
		return $row;
	}

	private function free(){
		if( $sqlResource ){
			mysql_free_result( $sqlResource );
			$sqlResource = NULL;
		}
	}

	__destruct(){
		$this->free();
	}

}

?>
